package com.base.kotlin

import android.app.Application
import androidx.lifecycle.scopeNetLife
import androidx.lifecycle.viewModelScope
import com.base.common.viewmodel.BaseViewModel
import com.drake.net.Get
import com.drake.net.Net
import com.kotlin.base.di.getCoroutineContext
import com.kotlin.base.net.request
import com.kotlin.base.utils.KJson
import com.tao.data.Resource
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.buildJsonObject
import okhttp3.Headers
import javax.inject.Inject
import kotlin.coroutines.coroutineContext

@HiltViewModel
class MainViewModel @Inject constructor( context: Application) : BaseViewModel (context) {
//HeadersHashMap<String, Object> map = new HashMap<String, Object>();
//        map.put("LoginId", "a001");
//        map.put("password", "Abcd12345678");
//        map.put("Lang",1);
     var stateView:MutableStateFlow<Resource<Login>> = MutableStateFlow(Resource.Start())



      val a= flow<Login> {
       var result= Net.get("http://192.168.60.36:3635/api/Login"){

           setHeaders(Headers.headersOf("LoginId","a002","password","Abcd12345678","Land","1")
           )
           param("DeviceType",1)
       }.execute<Login>()
          emit(result)
      }.flowOn(Dispatchers.IO)




        fun getData(){




            viewModelScope.launch {


               request(a,stateView)
            }
        }




}